import requests

# 定义请求的url
url = 'https://fanyi.baidu.com/sug'

# 定义请求的头信息
headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0'
}    # headers 换头
mess = input('请输入你要翻译的内容：')
data = {'kw': mess}
# 发送请求
res = requests.post(url=url,headers=headers,data=data)

code = res.status_code # 响应的状态码
if code == 200:
    print('请求成功')
    data_2 = res.json() # 接收返回数据
    print(data_2)
    if data_2['errno'] == 0:
        print('响应成功')
        k = data_2['data'][0]['k']  # 分析返回的数据
        v = data_2['data'][0]['v'].split(';').pop(-2)
        print(k +' ','==',v)
